﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using MyDLL;

namespace winform_用户界面客户端
{
    public partial class MainForm : Form
    {

        public string version = "v.0.0.0.1";

        public MySqlite m;
        public List<MySqlite> SBT_DBs=new List<MySqlite>();//各个标签数据库

        public MainForm()
        {
            InitializeComponent();
        }

        //保持数据库连接，重置一切。
        private void Clear()
        {
            include_TagName.Clear();
            exclude_TagName.Clear();
            Update_RTB_TagSearch();
            LV_Result.Items.Clear();
            LV_Tags_List.Items.Clear();
            Close_DBs();
            SBT_DBs.Clear();
        }

        /// <summary>
        /// 打开数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void RTB_Open_DB_Click(object sender, EventArgs e)
        {
            Clear();
            string[] DBs = RTB_DB_Path.Text.Split('\n');
            //参数检测
            if(DBs.Length==0)
            {
                MyOutPut("无法识别数据库路径");
                return;
            }
            //打开数据库
            foreach (string s in DBs.Distinct())    //去除重复
            {
                MySqlite temp_m = new MySqlite();
                temp_m.Create_Open_DB(s);                
                SBT_DBs.Add(temp_m);
                MyOutPut(s + " 已打开");
            }            
            MyOutPut("数据库打开成功");
            Get_Tag_Click(sender, e);
        }

        /// <summary>
        /// 用于将列表LV_Tag_List中的部分记录加粗显示
        /// </summary>
        private HashSet<string> Tags_List_TagName = new HashSet<string>();

        /// <summary>
        /// LV_Result中标签的分割符
        /// </summary>
        private string LV_Result_Tag_spliter = ";";

        /// <summary>
        /// 根据标签搜索目标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void BTN_Search_Click0(object sender, EventArgs e)
        {     
            //List<string> TargetsName = m.Get_Targets_By_Tag(RTB_TagSearch.Text,RTB_TagSplit.Text.ToString()[0]);
            if(include_TagName.Count==0&&exclude_TagName.Count==0)
            {
                LV_Result.Items.Clear();
                Tags_List_TagName.Clear();
                LV_Tags_List_Font_Bold();
            }
            Tags_List_TagName.Clear();  //清空 用于加粗显示标签的列表
            List<List<string>> last_result = new List<List<string>>();  //显示在屏幕上的最终结果集
            List<string> temp_result = new List<string>();
            foreach (MySqlite m in SBT_DBs)
            {
                string m_dirPath=new FileInfo(m.DB_Path).DirectoryName+"\\";
                List<int> TargetID = m.Get_TargetID_By_Tag_List(include_TagName, exclude_TagName);
                if (TargetID == null)
                {
                    MyOutPut(m.DB_Path+" 搜索结果为0");
                    continue;
                }
                
                List<List<string>> TargetsName =new  List<List<string>>();//记录在当前数据库中找到的目标名

                //下方代码逻辑有点混乱
                foreach (int id in TargetID)
                {
                    List<string> Target_temp = m.Get_Target_By_ID(id);                    
                    if (Target_temp != null)
                    {
                        //TargetsName.Add(Target_temp[1]);
                        temp_result.Clear();
                        temp_result.Add(Target_temp[1]);
                        TargetsName.Add(new List<string>(temp_result));//完善last_result[0]                      
                        //last_result.Add(temp_result);//！！！：这个是错误写法，会导致原本添加的temp_result数据被替换为最新的，因为都是temp_result的引用
                        /*
                        for (int i=0;i<last_result.Count;i++)
                            for (int j = 0; j < last_result[i].Count; j++)
                                MyOutPut("test"+i.ToString()+","+j.ToString()+" : "+ last_result[i][j]);
                        */
                    }
                }
                
                //查找当前数据库中相关目标的标签                
                List<string> temp;                
                foreach (List<string> record in TargetsName)
                {
                    temp = m.Get_Tags_By_TargetName(record[0]);
                    if (temp == null)
                    {
                        MyOutPut("null : " + record[0]);
                        continue;
                    }
                    record.Add(string.Join(LV_Result_Tag_spliter, temp)); //完善last_result[1]                    
                    foreach (string i in temp)
                    {
                        Tags_List_TagName.Add(i);   //用于加粗标签列表中的标签文字
                    }
                    record.Add(m_dirPath);//完善last_result[2]，即文件所在路径

                    last_result.Add(record);
                }

                
            }
            
            //开始显示到界面上
            this.LV_Result.BeginUpdate();
            this.LV_Result.Items.Clear();
            for (int i = 0; i < last_result.Count; i++)
            {
                ListViewItem lvi = new ListViewItem();

                lvi.Text = (i + 1).ToString();
                lvi.SubItems.Add(last_result[i][0]);    //添加目标名 
                lvi.SubItems.Add(last_result[i][1]);  //添加标签名
                lvi.SubItems.Add(last_result[i][2]);  //添加"所在路径"
                this.LV_Result.Items.Add(lvi);
            }
            this.LV_Result.EndUpdate();
            LV_Tags_List_Font_Bold();
        }

        /// <summary>
        /// 根据搜索结果，对指定标签加粗
        /// </summary>
        private void LV_Tags_List_Font_Bold()
        {
            //将加粗字体还原为不加粗字体
            foreach (ListViewItem item in LV_Tags_List.Items)
                item.Font = new Font(DefaultFont, FontStyle.Regular);
            //加粗指定标签
            foreach (string tag in Tags_List_TagName)
                foreach (ListViewItem item in LV_Tags_List.Items)
                {
                    if (item.SubItems[1].Text == tag)
                    {
                        item.Font = new Font(DefaultFont, FontStyle.Bold);
                        break;
                    }
                }
        }

        /// <summary>
        /// 为文件创建硬链接
        /// </summary>
        /// <param name="linkName">新文件绝对路径</param>
        /// <param name="sourceName">源文件绝对路径</param>
        /// <param name="attribute"></param>
        /// <returns></returns>
        [DllImport("Kernel32", CharSet = CharSet.Unicode)]
        public extern static bool CreateHardLink(string linkName, string sourceName, IntPtr attribute);

        /// <summary>
        /// 为所选目标创建硬链接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BTN_Hardlink_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(RTB_Hardlink_Path.Text))   
            {   //如果不存在则创建
                Directory.CreateDirectory(RTB_Hardlink_Path.Text);
            }

            //获取文件所在文件夹
            //string source_Path = Path.GetDirectoryName(RTB_DB_Path.Text)+"\\";

            //为列表中的目标创建硬链接
            int total = LV_Result.Items.Count;
            string target_name,target_path;
            bool result = true;
            foreach(ListViewItem i in LV_Result.Items)
            {                
                target_name = i.SubItems[1].Text;//获取Target的名字
                target_path = i.SubItems[3].Text;//获取Target的路径
                //创建硬链接
                if (Directory.Exists(target_path + target_name))
                    result=HardLink_For_Folder(RTB_Hardlink_Path.Text + target_name + "/", target_path + target_name + "/");
                else
                    result =CreateHardLink(RTB_Hardlink_Path.Text + target_name, target_path + target_name, IntPtr.Zero);
                MyOutPut(RTB_Hardlink_Path.Text + target_name + "来自" + target_path + target_name+" "+result);                
                //导出标签信息
                if(CB_withTags.CheckState==CheckState.Checked)
                {
                    MySqlite m = GlobalValue.OpenDB(RTB_Hardlink_Path.Text);
                    //获取Target标签
                    List<string> tags = i.SubItems[2].Text.Split(LV_Result_Tag_spliter[0]).ToList();
                    foreach(string t in tags)
                    {
                        m.Add_Map_Target_Tag(target_name, t);
                    }
                }
            }


        }

        private void BTN_Test(object sender, EventArgs e)
        {
            
        }

        /// <summary>
        /// 为文件夹中的文件创建硬链接
        /// </summary>
        /// <param name="new_fullPath">新文件夹完整绝对路径。如新文件夹Test1 即为"E:/Test1/"</param>
        /// <param name="src_fullPath">原始文件夹完整绝对路径。如原始文件夹为src 即为"E:/src/"</param>
        /// <returns></returns>
        private bool HardLink_For_Folder(string new_fullPath,string src_fullPath)
        {
            if(!Directory.Exists(new_fullPath))
                Directory.CreateDirectory(new_fullPath);           
            
            DirectoryInfo src_dir = new DirectoryInfo(src_fullPath);
            DirectoryInfo new_dir= new DirectoryInfo(new_fullPath);

            FileInfo[] fileInfo = src_dir.GetFiles();
            bool result;
            foreach(FileInfo f in fileInfo)
            {
                result=CreateHardLink(new_dir.FullName + f.Name, f.FullName, IntPtr.Zero);               
            }
            DirectoryInfo[] dirInfo = src_dir.GetDirectories();
            foreach (DirectoryInfo d in dirInfo)
            {                
                HardLink_For_Folder(new_dir.FullName + d.Name+"/", d.FullName+"/");
            }
            return true;
        }

        public void MyOutPut(string text)
        {
            RTB_Log.Text += RTB_Log.Text == "" ? text : "\n" + text;
            RTB_Log.SelectionStart = RTB_Log.Text.Length;
            RTB_Log.ScrollToCaret();
        }

        /// <summary>
        /// 按钮：更新标签的被引用次数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RTB_ReFresh_Tag_Refer_Click(object sender, EventArgs e)
        {
            foreach(MySqlite temp_m in SBT_DBs)
                temp_m.ReFresh_Tag_Refer();
            MyOutPut("标签的被引用次数 已更新完毕");
        }

        /// <summary>
        /// 获取标签列表（按被引用数排序的前100个
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Get_Tag_Click(object sender, EventArgs e)
        {
            List<List<string>> last_result = new List<List<string>>();//最终要显示在控件中的数据库
            foreach (MySqlite sbt in SBT_DBs)
            {
                //获取标签ID
                List<int> Tags_ID = sbt.Get_All_Tag_ID("desc", 400, 0);
                //获取标签完整信息
                List<List<string>> Tags = new List<List<string>>();
                foreach (int i in Tags_ID)
                {
                    List<string> temp_tag = sbt.Get_Tag_By_ID(i);
                    temp_tag.RemoveAt(0);//删掉id，因为没用
                    //检测是否已经存在
                    bool checkFlag = false;
                    foreach(List<string> last_tag in last_result)
                    {
                        if (temp_tag[0] == last_tag[0] && temp_tag[1] == last_tag[1])//比较标签名和标签备注
                        {
                            //引用数合并
                            if (temp_tag[2] != "" && last_tag[2] != "")
                            {
                                int a = int.Parse(last_tag[2]);//!:这里应该可以优化
                                int b = int.Parse(temp_tag[2]);
                                last_tag[2] = (a + b).ToString();
                                checkFlag = true;
                            }
                            break;
                        }
                    }
                    if (checkFlag == false)
                        last_result.Add(temp_tag);                    
                }
            }
            //处理引用数为空的情况
            foreach(List<string> ls in last_result)
            {
                if (ls[2] == "")
                    ls[2] = (-1).ToString();
            }

            //对最终结果进行排序
            last_result.Sort((x, y) => (int.Parse(x[2]) > int.Parse(y[2])) ? -1 : 1);

            //开始显示到界面上
            LV_Tags_List.BeginUpdate();            
            ListViewGroup all_lvg = LV_Tags_List.Groups[1];
            all_lvg.Items.Clear();
            for (int i = 0; i < last_result.Count; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = (i + 1).ToString();
                //lvi.SubItems.Add(Tags[i][0]);    //添加标签ID
                lvi.SubItems.Add(last_result[i][0]);  //添加标签名

                lvi.SubItems.Add(last_result[i][2]);  //添加被引用次数
                lvi.SubItems.Add(last_result[i][1]);  //添加备注
                //lvi.Group = all_lvg;
                all_lvg.Items.Add(lvi);
                LV_Tags_List.Items.Add(lvi);
            }
            LV_Tags_List.EndUpdate();
        }

        private List<string> include_TagName = new List<string>();
        private List<string> exclude_TagName = new List<string>();
        /// <summary>
        /// 更新UI：对搜索关键词的文本框进行更新。
        /// </summary>
        private void Update_RTB_TagSearch()
        {
            RTB_TagSearch.Clear();
            RTB_TagSearch.Text = string.Join("+", include_TagName.ToArray());
            if (exclude_TagName.Count != 0)
                RTB_TagSearch.Text += "-" + string.Join("-", exclude_TagName.ToArray());
        }

        /// <summary>
        /// 事件函数：在标签列表中点击标签项。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LV_Tags_List_OnClick(object sender, MouseEventArgs e)
        {
            //处理选中的内容
            string TagName = LV_Tags_List.SelectedItems[0].SubItems[1].Text.ToString();
            if (e.Button == MouseButtons.Left)
            {
                //RTB_TagSearch.Text += RTB_TagSearch.Text == "" ? Tag : RTB_TagSplit.Text + Tag;//
                MyOutPut("左键单击了 " + TagName);
                if (exclude_TagName.Contains(TagName))
                    exclude_TagName.Remove(TagName);
                else if(!include_TagName.Contains(TagName))
                    include_TagName.Add(TagName);
                
            }
            else if(e.Button==MouseButtons.Right)
            {
                MyOutPut("右键单击了 "+ TagName);
                if (include_TagName.Contains(TagName))
                    include_TagName.Remove(TagName);
                else if(!exclude_TagName.Contains(TagName))
                    exclude_TagName.Add(TagName);
            }
            else
            {
                MyOutPut("其他鼠标事件:" + e.Button.ToString());
            }
            Update_RTB_TagSearch();
            if (include_TagName.Count == 0&&exclude_TagName.Count!=0)
                MyOutPut("仅包含‘非’标签，暂时不能搜索");
            else
                BTN_Search_Click0(sender, e);            
        }

        /// <summary>
        /// 测试用按钮。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            
            /*
            MyOutPut("检测中");
            Process[] processes= Process.GetProcessesByName("photolaunch");
            MyOutPut(processes.Length.ToString());            
            if (processes.Length!=0)
            {
                foreach (Process i in processes)
                {                    
                    MyOutPut(i.MainWindowTitle);
                }
                
            }
            else
            {
                MyOutPut("不包含元素");
            }
            
            MyOutPut("检测完毕");*/
        }

        /// <summary>
        /// 事件函数。当标签搜索框的内容改变时发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RTB_Tag_Input_Changed(object sender, EventArgs e)
        {           
            //本段代码的功能：用户按下回车后才执行搜索
            if (RTB_Tag_Input.Text != ""&&RTB_Tag_Input.Text[RTB_Tag_Input.Text.Length - 1] != '\n')
                return;
            else
            {
                RTB_Tag_Input.Text = RTB_Tag_Input.Text.Replace("\n", "");
                
                RTB_Tag_Input.SelectionStart = RTB_Tag_Input.TextLength;
            }

            ListViewGroup search_lvg = LV_Tags_List.Groups[0];//标签集合ListView中第0组的标签组
            //清空搜索记录
            while (search_lvg.Items.Count != 0) 
            {
                LV_Tags_List.Items.Remove(search_lvg.Items[0]);
            }
            if (RTB_Tag_Input.Text == "")   //防止用户没有输入数据只敲一个回车，放在这里同时可以用作清空搜索结果
                return;

            List<List<string>> last_result = new List<List<string>>();
            foreach (MySqlite sbt in SBT_DBs)
            {
                List<int> Tags_ids = sbt.Find_Tag_By_Name("fuzzy", "%" + RTB_Tag_Input.Text + "%");

                if (Tags_ids[0] == -1)
                {
                    MyOutPut(sbt.DB_Path+" 没有符合条件的标签");
                    continue;
                }
                //获取标签完整信息
                List<List<string>> Tags = new List<List<string>>();
                foreach (int Tags_id in Tags_ids)
                {
                    List<string> temp_result = sbt.Get_Tag_By_ID(Tags_id);
                    //检测last_result是否已经存在
                    bool checkFlag = false;
                    foreach(List<string> last in last_result)
                    {
                        if(temp_result[1]==last[1]&&temp_result[2]==last[2])//如果标签已经存在
                        {
                            last[3] = (int.Parse(temp_result[3]) + int.Parse(last[3])).ToString();
                            checkFlag = true;
                            break;
                        }
                    }
                    if (checkFlag == false)
                        last_result.Add(temp_result);
                }
            }
            //更新界面上的数据
            LV_Tags_List.BeginUpdate();

            while (search_lvg.Items.Count != 0)//清空界面的数据
            {                
                LV_Tags_List.Items.Remove(search_lvg.Items[0]);
            }
            for (int i = 0; i < last_result.Count; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = (i + 1).ToString();
                //lvi.SubItems.Add(Tags[i][0]);    //添加标签ID
                lvi.SubItems.Add(last_result[i][1]);  //添加标签名

                lvi.SubItems.Add(last_result[i][3]);  //添加被引用次数
                lvi.SubItems.Add(last_result[i][2]);  //添加备注
                //lvi.Group = search_lvg;
                
                search_lvg.Items.Add(lvi);
                LV_Tags_List.Items.Add(lvi);
            }
            //部分标签加粗显示
            foreach (string tag in Tags_List_TagName)
                foreach (ListViewItem item in search_lvg.Items)
                {
                    if (item.SubItems[1].Text == tag)
                    {
                        item.Font = new Font(DefaultFont, FontStyle.Bold);
                        break;
                    }
                }
                
            //LV_Tags_List_Font_Bold();//？：不知道为什么不会刷新
            LV_Tags_List.EndUpdate();
            
        }


        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            MyOutPut("正在关闭数据库连接");
            Close_DBs();
            MyOutPut("数据库已关闭");
        }

        private void Close_DBs()
        {
            foreach (MySqlite temp_m in SBT_DBs)
            {
                temp_m.Close_DB();                
            }
        }

        private void LV_Tags_List_ColumnClick(object sender, ColumnClickEventArgs e)
        {            
            if(e.Column.ToString()=="2")
            {
                LV_Tags_List.Sorting = SortOrder.Ascending;
                    //更新界面上的数据
            //last_result.Sort((x, y) => (int.Parse(x[2]) > int.Parse(y[2])) ? 1 : 0);
            }
        }

        private void LV_Result_DragDrop(object sender, DragEventArgs e)
        {
            string filename = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            //查找当前列表中的对应项，并标记为“选中”
            //注：这条需求是我想从导出后的目标间接修改源目标的标签，思路尚不成熟，暂不编写。
            
        }

        private void LV_Result_DragEnter(object sender, DragEventArgs e)
        {
            string filename = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            MyOutPut(filename);
            e.Effect = DragDropEffects.Link;
        }

        private void 打开文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了打开文件");
        }

        private void LV_Result_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListView lv = sender as ListView;
            if (lv == null)
                return;

            ListViewHitTestInfo info = lv.HitTest(e.X, e.Y);
            ListViewItem curItem = info.Item; // 获取双击时选中的row
            //int colIdx = info.Item.SubItems.IndexOf(info.SubItem); // 得到双击的column
            /*for(int i=0;i<curItem.SubItems.Count;i++)
            {
                MyOutPut(curItem.SubItems[i].Text);
            }*/
            string targetFullPath = curItem.SubItems[3].Text + curItem.SubItems[1].Text;
            //在资源管理器中定位文件
            /*
            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
            psi.Arguments = "/e,/select," + targetFullPath;
            System.Diagnostics.Process.Start(psi);*/

            //运行文件
            if(File.Exists(targetFullPath))
                System.Diagnostics.Process.Start(targetFullPath);
            else if(Directory.Exists(targetFullPath))//打开文件夹
            {
                System.Diagnostics.Process.Start("explorer.exe",targetFullPath);
                /*//定位文件
                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
                psi.Arguments = "/e,/select," + targetFullPath;
                System.Diagnostics.Process.Start(psi);*/
            }
            else
            {
                MyOutPut("所选项既不是文件也不是文件夹");
            }
        }

        private void LV_Result_MouseClick(object sender, MouseEventArgs e)
        {
            MyOutPut("点击时间1:" + DateTime.Now.Millisecond.ToString());
            ListView lv = sender as ListView;
            if (lv == null)
                return;

            ListViewHitTestInfo info = lv.HitTest(e.X, e.Y);
            ListViewItem curItem = info.Item; // 获取双击时选中的row
            string targetFullPath = curItem.SubItems[3].Text + curItem.SubItems[1].Text;
            //运行文件
            if (File.Exists(targetFullPath))
            {     
                //pictureBox1.Image = Image.FromFile(targetFullPath);
                pictureBox1.LoadAsync(targetFullPath);
            }
            else
            {
                pictureBox1.Image = null;
            }
            MyOutPut("点击时间2:"+DateTime.Now.Millisecond.ToString());
        }

        private void LV_Result_SelectedIndexChanged(object sender, EventArgs e)
        {
            //选择不同的item项时，此事件会执行两次。//第一次是取消，此时SelectedIndices.Count变为1
            //第二次才将新选中的Item设置为选中状态，SelectedIndices变为1
            if (LV_Result.SelectedIndices.Count > 0)
            {
                ListView lv = sender as ListView;
                if (lv == null)
                    return;

                ListViewItem curItem = lv.SelectedItems[0];
                string targetFullPath = curItem.SubItems[3].Text + curItem.SubItems[1].Text;
                //运行文件
                if (File.Exists(targetFullPath))
                {
                    pictureBox1.Image = Image.FromFile(targetFullPath);
                }
                else
                {
                    pictureBox1.Image = null;
                }
            }
        }

        private void BTN_Search_Click(object sender, EventArgs e)
        {
            include_TagName.Clear();
            exclude_TagName.Clear();
            //处理搜索框中的数据
            string input = RTB_TagSearch.Text;
            input = "+" + input;
            MatchCollection mc=Regex.Matches(input, @"([\+\-].+?(?=[\+\-]))|([\+\-].+?$)");            
            foreach (Match m in mc)
            {
                string TagName = m.Value.Substring(1);
                if (m.Value[0]=='+')
                {
                    //RTB_TagSearch.Text += RTB_TagSearch.Text == "" ? Tag : RTB_TagSplit.Text + Tag;//
                    MyOutPut("左键单击了 " + TagName);
                    if (exclude_TagName.Contains(TagName))
                        exclude_TagName.Remove(TagName);
                    else if (!include_TagName.Contains(TagName))
                        include_TagName.Add(TagName);

                }
                else if (m.Value[0] == '-')
                {
                    MyOutPut("右键单击了 " + TagName);
                    if (include_TagName.Contains(TagName))
                        include_TagName.Remove(TagName);
                    else if (!exclude_TagName.Contains(TagName))
                        exclude_TagName.Add(TagName);
                }
                else
                {
                    MyOutPut("未知的搜索间隔符："+ m.Value[0]);
                }                
            }
            //Update_RTB_TagSearch();
            if (include_TagName.Count == 0 && exclude_TagName.Count != 0)
                MyOutPut("仅包含‘非’标签，暂时不能搜索");
            else
                BTN_Search_Click0(sender, e);
        }

        private void pictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }

        private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            MyOutPut("加载完成:" + DateTime.Now.Millisecond.ToString());
        }
    }
}
